package com.sx.pipeline.ui.examine.info

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.bumptech.glide.Glide
import com.gyf.immersionbar.ImmersionBar
import com.lxj.xpopup.XPopup
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.arouth.RoutePath.Mine.EXAMINE_PERSON_INFO
import com.sx.pipeline.databinding.ActExaminePersonalInfoBinding
import com.sx.pipeline.ui.examine.manager.ExamineManagerVM


@Route(path = EXAMINE_PERSON_INFO)
class ExaminePersonalInfoAct :
    CYDataBindingBaseActivity<ActExaminePersonalInfoBinding, ExamineManagerVM>(R.layout.act_examine_personal_info) {

    @Autowired
    @JvmField
    var id: String =""

    @Autowired
    @JvmField
    var option: Boolean =false

    override fun initData() {
        super.initData()
        ImmersionBar.with(this)
            .fitsSystemWindows(true)
            .statusBarColor(R.color.color_0188ff)
            .statusBarDarkFont(false)
            .init()
        mViewModel.getExamineInfo(id)
        mBinding.titleBar.leftView.setOnClickListener {
            finish()
        }
        mBinding.tvAgree.setOnClickListener {
            XPopup.Builder(this)
                .asConfirm("提示","确定要审核通过吗？"){
                    mViewModel.optionAudit(id.toInt(),true)
                }.show()
        }
        mBinding.tvCancel.setOnClickListener {
            XPopup.Builder(this)
                .asInputConfirm("请填写驳回原因",null){
                    mViewModel.optionAudit(id.toInt(),false)
                }.show()
        }
    }
    override fun initViewObservable() {
        super.initViewObservable()
        mViewModel.examineInfoLiveData.observe(this) {
            it?.let {
                Glide.with(this).load(it?.avatar).placeholder(R.mipmap.ic_default_head)
                    .into(mBinding.ivAvatar)
                mBinding.tvName.text = it.userName.orEmpty()
                mBinding.sbGender.rightText = if(it.sex==0) "男" else "女"
                mBinding.sbPhone.rightText = it.phone.orEmpty()
                mBinding.sbJob.rightText = it.occupation.orEmpty()
                mBinding.sbSubtime.rightText=it.createTime.orEmpty()
                mBinding.sbShTime.rightText=it.updateTime.orEmpty()
                mBinding.sbRjTime.rightText=it.updateTime.orEmpty()
                mBinding.sbCancelTime.rightText=it.updateTime.orEmpty()
                mBinding.sbRemark.rightText=it.remark.orEmpty()
                mBinding.sbRjReason.rightText=it.reject.orEmpty()
                mBinding.titleBar.title=if(it.status==0) "待审核" else if(it.status==1) "已通过" else if(it.status==2) "已驳回" else "已取消"
                if(it.status==1){
                    mBinding.sbShTime.visibility= View.VISIBLE
                }else if(it.status==2){
                    mBinding.sbRjReason.visibility=View.VISIBLE
                    mBinding.sbRjTime.visibility=View.VISIBLE
                }else if(it.status==3){
                    mBinding.sbCancelTime.visibility=View.VISIBLE
                }else if(it.status==0){
                    if(option){
                        mBinding.tvAgree.visibility=View.VISIBLE
                        mBinding.tvCancel.visibility=View.VISIBLE
                    }
                }
            }
        }
        mViewModel.refreshEvent.observe(this){
            mViewModel.getExamineInfo(id)
        }
    }
}